package yagwl.service.fnd.flex;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import yagwl.service.util.CryptoUtil;

@SuppressWarnings("serial")
@Entity
@Table(name = "M_FLEX_ENTITY")
public class FlexEntityEntity implements Serializable {

  private static final String entityCode = "ENT";

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = "ENTITY_ID")
  private Long entityId;
  
  @Column(name = "NAME")
  private String name;
  
  @Column(name = "PARENT_ENTITY")
  private String parentEntity;

  @Column(name = "ATTRIBUTE_IDS")
  private List<Long> attributeIds = new ArrayList<Long>();

  @Transient
  private List<FlexAttributeEntity> attributes = new ArrayList<FlexAttributeEntity>();

  Long getEntityId() {
    return entityId;
  }

  void setEntityId(Long entityId) {
    this.entityId = entityId;
  }

  public String getEncryptedEntityId() {
    return encryptId(entityId);
  }

  public void setEncryptedEntityId(String id) {
    entityId = decryptId(id);
  }
  
  static String encryptId(Long id) {
    return CryptoUtil.encryptLong(id, entityCode);
  }

  static Long decryptId(String id) {
    return CryptoUtil.decryptLong(id, entityCode);
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getParentEntity() {
    return parentEntity;
  }

  public void setParentEntity(String parentEntity) {
    this.parentEntity = parentEntity;
  }

  public void setAttributeIds(List<Long> attributeIds) {
    this.attributeIds = attributeIds;
  }

  public List<Long> getAttributeIds() {
    return attributeIds;
  }

  public void setAttributes(List<FlexAttributeEntity> attributes) {
    this.attributes = attributes;
  }

  public List<FlexAttributeEntity> getAttributes() {
    return attributes;
  }

}